package function;

public class fun5 {
    public static void main(String[] args) {
        int [] userChooseNumber;
        int [] goalNumber;
        for (var j = 1;true;j++){
            userChooseNumber = createNumber();
            goalNumber = createNumber();
            for (int k : userChooseNumber) {
                System.out.print(k + " ");
            }
            System.out.println(" ");
            for (int k : goalNumber) {
                System.out.print(k + " ");
            }
            System.out.println(" ");
            String result = judgeWinner(userChooseNumber, goalNumber);
            switch (result) {
                    case "61":
                        System.out.println("恭喜您获得一等奖,1000万,共实验"+j+"次");
                        break;
                    case "60":
                        System.out.println("恭喜您获得二等奖,500万，共实验"+j+"次");
                        break;
                    case "51":
                    case "50":
                        System.out.println("恭喜您获得三等奖,3000元，共实验"+j+"次");
                        break;
                    case "41":
                    case "40":
                        System.out.println("恭喜您获得四等奖,200元，共实验"+j+"次");
                        break;
                    case "31":
                        case "30":
                        System.out.println("恭喜您获得五等奖,10元，共实验"+j+"次");
                        break;
                    case "21":
                        case "20":
                        System.out.println("恭喜您获得六等奖,5元，共实验"+j+"次");
                        break;
                    case "11":
                        case "10":
                        System.out.println("恭喜您获得七等奖,2元，共实验"+j+"次");
                        break;
                    case "01":
                        System.out.println("恭喜您获得八等奖,1元，共实验"+j+"次");
                        break;
                    default:
                        System.out.println("很遗憾，没有中奖");
                }
            if (!result.equals("00")) {
                break;
            }
        }
    }

    public static int[] createNumber() {
        int [] arr = new int[7];
        for (int i = 0; i < 6;) {
            int num = (int) (Math.random() * 33);
            if (!isExist(num, arr)) {
                arr[i] = num;
                i++;
            }
        }
        arr[6] = (int) (Math.random() * 16);
        return arr;
    }

    public static boolean isExist(int num , int [] arr){
        boolean flag = false;
        for (int j : arr) {
            if (j == num) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public static String judgeWinner(int [] userChooseNumber, int [] goalNumber) {
        int redCount = 0;
        int blueCount = 0;
        for (int i = 0; i < userChooseNumber.length; i++) {
            if(userChooseNumber[i] == goalNumber[i]) {
                redCount++;
            }
            if(i == userChooseNumber.length - 1 && userChooseNumber[i] == goalNumber[i]){
                blueCount++;
            }
        }
        return String.valueOf(redCount) + blueCount;
    }
}
